#include "userpage.h"
#include "ui_userpage.h"
#include "login.h"
#include "database.h"

UserPage::UserPage(QWidget *parent):
    QWidget(parent),
    ui(new Ui::UserPage)
{
    ui->setupUi(this);
    ui->label_Now_username->setText(Now_Username);//获取用户名
    ui->stackedWidget->setCurrentIndex(0);//默认界面为HomePage



}

UserPage::~UserPage()
{
    delete ui;
}


//清除输入的数据
void UserPage::on_pushButton_page2_clear_clicked()
{
    ui->lineEdit_page2_nowPwd->clear();
    ui->lineEdit_page2_newPwd->clear();
    ui->lineEdit_page2_newPwdAgain->clear();
}

//确认修改
void UserPage::on_pushButton_page2_ok_clicked()
{
    QString nowPwd = ui->lineEdit_page2_nowPwd->text();
    QString newPwd = ui->lineEdit_page2_newPwd->text();
    QString newPwdAgain = ui->lineEdit_page2_newPwdAgain->text();
    if(nowPwd.isEmpty()||newPwd.isEmpty()||newPwdAgain.isEmpty())//检查是否有空
    {
        QMessageBox::information(NULL,"警告","请将数据填写完整",QMessageBox::Ok);
    }
    else
    {
        if(nowPwd==newPwd||nowPwd==newPwdAgain||newPwd!=newPwdAgain)//检查是否输入的新密码和原始密码一致
        {
            QMessageBox::information(NULL,"警告","密码与原密码一致或新密码不一致",QMessageBox::Ok);
        }
        else
        {
            if(Now_Password==ui->lineEdit_page2_nowPwd->text())//检查当前密码是否正确
            {
                DataBase::updatePassword(Now_Username,newPwd);
                qDebug() << "更新密码成功";
            }
            else
            {
                QMessageBox::information(NULL,"警告","密码错误",QMessageBox::Ok);
            }
        }
    }
}

//个人信息修改
void UserPage::on_pushButton_personaLinfoPage_changeInfo_clicked()
{

}
//个人信息修改确认
void UserPage::on_pushButton_personaLinfoPage_ok_clicked()
{

}



//左侧工具栏点击切换界面
void UserPage::on_listWidget_clicked(const QModelIndex &index)
{
//    qDebug()<<index;
//    qDebug()<<index.row();
    switch (index.row()) {
    case 0:ui->stackedWidget->setCurrentIndex(0);break;//切换到HomePage
    case 1:ui->stackedWidget->setCurrentIndex(1);break;//切换到个人信息界面
    case 2:ui->stackedWidget->setCurrentIndex(2);break;//切换到修改密码界面
    }
}
